package com.LeeCode;

/**
 * 零数组变换 I
 */

public class Code3355 {
    public static void main(String[] args) {
        int[] nums = {1, 0, 1};
        int[][] queries = {{0, 2}};
        System.out.println(new Code3355().isZeroArray(nums, queries));
    }

    public boolean isZeroArray(int[] nums, int[][] queries) {
        int[] count = new int[nums.length + 1];
        for (int[] query : queries) {
            count[query[0]]++;
            count[query[1] + 1]--;
        }

        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += count[i];
            if (nums[i] != 0 && sum < nums[i]) {
                return false;
            }
        }
        return true;
    }
}
